package Leetcode;

public class Leetcode_35 {
        public static int maxScoreSightseeingPair(int[] values) {
            int ans = 0, mx = values[0] + 0;
            for (int j = 1; j < values.length; ++j) {
                ans = Math.max(ans, mx + values[j] - j);
                // 边遍历边维护
                mx = Math.max(mx, values[j] + j);
            }
            return ans;
        }
    public static void main(String[] arr1){
        int[] values = {8,1,5,2,6};
        System.out.println(maxScoreSightseeingPair(values));
    }
}
